<!--  -->
<template>
  <div style="margin-top: 15px">
    <el-table
      border
      :data="list"
      style="width: 100%"
      :header-cell-style="{
        background: '#fafafa',
        color: '#333',
        fontWeight: '600',
        textAlign: 'center',
        fontSize: '14px',
      }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column
        v-for="item in tableList"
        :key="item.label"
        :label="item.label"
        :prop="item.prop"
        align="center"
      >
        <template slot-scope="scope">
          <span v-if="item.prop == 'typename'">
            <el-link type="primary">{{ scope.row.typename }}</el-link></span
          >
          <span v-if="item.prop == 'title'">{{ scope.row.title }}</span>
          <span v-if="item.prop == 'picture'">
            <el-image
              style="width: 50px; height: 50px"
              :src="
                'http://estate.eshareedu.cn/estate/upload/' + scope.row.picture
              "
              :preview-src-list="'http://estate.eshareedu.cn/estate/upload/' + scope.row.picture"
            ></el-image>
          </span>
          <span v-if="item.prop == 'state'">
            <el-switch
              :value="scope.row.state"
              active-color="#13ce66"
              inactive-color="#ff4949"
              :active-value="1"
              :inactive-value="0"
              @change="changeStatus($event, scope.row)"
            >
            </el-switch
          ></span>
          <span v-if="item.prop == 'addtime'">{{ scope.row.addtime }}</span>
          <span v-if="item.prop == 'edituser'">{{ scope.row.edituser }}</span>
          <span v-if="item.type == 'button'">
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="updateList(scope.row)"
              circle
            ></el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              @click="delNews(scope.row.id)"
              circle
            ></el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  props: {
    list: {
      type: Array,
      default: () => [],
    },
    tableList: {
      type: Array,
      default: () => [],
    },
  },
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {};
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    changeStatus(callback, row) {
      let text = "";
      if (callback == 1) {
        text = "开启";
        row.state = 0;
      } else {
        text = "关闭";
        row.state = 1;
      }
      this.$confirm(`是否变更状态为${text}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        let message = "";
        if (row.state == 0) {
          row.state = 1;
          message = "开启成功";
        } else {
          row.state = 0;
          message = "关闭成功";
        }
        // 逻辑操作
        this.$message({
          type: "success",
          message,
        });
      });
    },
    //点击删除获取id
    delNews(id) {
      this.$emit("Newsdel", id);
    },
    //修改
    updateList(data) {
      this.$emit("updata", data);
    },
    //复选框选中的id
    handleSelectionChange(val) {
      this.$emit("multipleSelection", val);
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    console.log(this.tableList);
    console.log(this.list);
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped>
</style>